<%--
  Created by IntelliJ IDEA.
  User: 91228
  Date: 2022/8/4
  Time: 17:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>Title</title>
    <style>
        div{
            width: 900px;
            margin: 0 auto;
        }
        h1{
            text-align: center;

        }
        #trm{
            background-color: green;
        }
    </style>
</head>
<body>
<div>
    <%
        String str=(String)request.getAttribute("mess");
        if(str!=null){
            out.println(str);
        }
    %>
    <form action="${pageContext.request.contextPath}/book/add" method="post" onsubmit="return validateForm()">
        <table border="1">
            <tr id="trm">
                <td colspan="2"><h1>增加电子图书</h1></td>
            </tr>
            <tr>
                <td >图书名称<span style="color:red">(*)</span></td>
                <td><input type="text" name="title" id="title"></td>
            </tr>
            <tr>
                <td>图书摘要</td>
                <td><textarea cols="70" rows="10"  name="summary"></textarea></td>
            </tr>
            <tr>
                <td >图书分类：</td>
                <td>
                    <select name="categoryId">
                    <option value="0">全部</option>
                        <c:forEach items="${addList}" var="list">
                            <option value="${list.id}">${list.name}</option>
                        </c:forEach>
                    </select>
                </td>
            </tr>
            <tr>
                <td >上传人</td>
                <td><input type="text" name="uploaduser" /></td>
            </tr>
            <tr>
                <td>上传时间<span style="color: red;">(*)</span></td>
                <td>
                    <input type="text" name="createdate" id="createdate"/>(yyyy-MM--dd)
                </td>
            </tr>
            <tr>
                <th colspan="2">
                    <input type="submit" value="提交"/>
                    <input type="button" value="返回" onclick="location.href='${pageContext.request.contextPath}/book/bookList.do'"/>
                </th>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    function validateForm(){
        //验证不能标题为空
        var title=document.getElementById("title").value;
        if(title==null||title.length==0){
            alert("图书名称不能为空！");
            return false;
        }
        //验证上传时间
        var createDate=document.getElementById("createdate").value;
        if(createDate==null||createDate.length==0){
            alert("上传时间不能为空");
            return false;
        }
        return true;
    }
</script>
</body>
</html>
